/*
 *  This file is part of "SchoolChoice",
 *  a school registration system.
 *
 *  Copyright (C) 2009 Nicolas Decerf, Olivier Jacquemin.
 *
 *  "SchoolChoice" is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  "SchoolChoice" is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program: see the file COPYING.txt.  If not, see
 *  http://www.gnu.org/licenses/.
 */

/*
 * Logger class.
 * Inspired by java.util.logging.Logger.
 */

/*global SchoolChoice */

(function() {
     // Private static data.

     var logLine = 0;


     // Private static methods.

     function addEntry(html, className) {
         var paragraph = document.createElement("p");
         paragraph.className = className;
         paragraph.innerHTML = html;
         document.getElementById("Log").appendChild(paragraph);
     }

     function log(message, isSevere) {
         logLine += 1;
         
         var now = new Date();
         var text = logLine + " -- " + now.toLocaleTimeString() + " -- " + message;
         var className = (isSevere ? "severe" : "");
         addEntry(text, className);
     }


     // Class and constructor declaration.
     SchoolChoice.WebAppClient.Logger = function() { };


     // Public static methods

     SchoolChoice.WebAppClient.Logger.info = function(message) {
         log(message, false);
     };

     SchoolChoice.WebAppClient.Logger.severe = function(message) {
         log(message, true);
     };
 }) ();
